<template>
  <div class="order-item">
    <el-row 
      style="width: 100%; display:flex; justify-content:flex-start; align-items: center; "
      flex="main:left cross:center"
    >
      <el-col :span="1">
        <el-checkbox
          v-model="checked"
          style="display: flex; justify-content:flex-start; align-items: center; "
          flex="main:left cross:center"
        ></el-checkbox>
      </el-col>
      <el-col :span="12" flex="main:left cross:center"
        style="display:flex; justify-content:flex-start; align-items: center; "
      >
        <el-image class="img" :src="orderItem.courseThumb"></el-image>
        <div class="order-content" flex="dir:top main:justify"
          style=" display:flex; justify-content: space-between; flex-direction: column; "
        >
          <p flex="main:justify" 
            style="display: flex; justify-content: space-between; "
          >
            <span class="text-ellipsis-single order-title">{{ orderItem.courseName }}</span>
            <span class="content-text"
              >
              <span class="font-primary">{{ courseType }}</span></span
            >
          </p>
          <p class="content-text order-text text-ellipsis-Multiline">
            {{ orderItem.briefDescribe }}
          </p>
        </div>
      </el-col>
      <el-col :span="3" class="font-primary fontWeight" >￥{{
        orderItem.discountPrice.toFixed(2)
      }}/{{orderItem.validYears}}年</el-col>
      <el-col :span="3" class="font-primary fontWeight">1</el-col>
      <el-col :span="3" class="font-primary fontWeight">￥{{
        orderItem.discountPrice.toFixed(2)
      }}</el-col>
      <el-col :span="2" class="font-info">
          <p  type="text" @click="deleteCart" class="deleate"  >删除</p>
      </el-col>
    </el-row>
  </div>
</template>

<script lang="ts">

//import { mapGetters } from "vuex";
import {delCart} from "/@/api/order"

import {useOptionsStore} from '/@/store/index';
const optionsStore = useOptionsStore();

export default {
  props: {
    orderItem: Object,
    allCheck: Boolean,
  },
  computed: {
    //...mapGetters(["lessonSorts"]),

  },
  data() {
    return {
      checked: false,
      courseType: '',
    };
  },
  mounted() {
    this.checked = this.orderItem.checked || false;
    this.getCourseType();
  },
  methods: {

    // 课程类型 firstCourseType-secondCourseType
    async getCourseType(){
      console.log(this.orderItem);
      let firstCourseType = {}, secondCourseType = {};
      await optionsStore.getCourseType(this.orderItem.firstTypeId).then((res) =>{
        firstCourseType = res;
        console.log(firstCourseType);
      });
      await optionsStore.getSecondCourseType(this.orderItem.secondTypeId).then((res) =>{
        secondCourseType = res;
        console.log(secondCourseType);
      });
      this.courseType = firstCourseType?.label + '-' + secondCourseType?.label;
      console.log(this.courseType );
    },
    deleteCart() { // 删除购物车
        delCart({courseId:this.orderItem.courseId}).then((res)=>{
          this.$emit('delete',this.orderItem.courseId)
          //this.$store.commit("user/SET_CART",res.total);
        })
        .catch(()=>{})
    }
  },
  watch: {
    allCheck(value) {
      this.checked = value;
    },
    checked(value) {
      this.$emit("checkChange", value);
    },
  },
};
</script>

<style lang="scss"  scoped>
.img {
  width: 184px;
  height: 100px;
  border-radius: 6px;
  flex-shrink: 0;
}
.el-col {
  height: 100%;
  text-align: center;
  padding: 4px;
}
.el-row {
  width: 100%;
}
.order-item {
  margin-bottom: 40px;
  font-size: 18px;
}

.order-title{
  width: 70%;
  text-align: left;
}
.order-content {
  padding: 0 20px;
  width: 424px;
  height: 100px;
}
.deleate{
  cursor: pointer;
  color: #808080;
  text-align:right
}
.order-text {
  text-align: left;

  -webkit-line-clamp: 2;
}
</style>